
function checkLogin() {
	return new Promise(function(resolve, reject) {
		if (uni.getStorageSync('userInfo') && uni.getStorageSync('openid')) {
			resolve(true);
		} else {
			reject(false);
		}
	});
}

function checkUserInfo() {
	const app = getApp();
	return new Promise(function(resolve, reject) {
		if (app.globalData.userInfo.name == '' && app.globalData.userInfo.mobile == '') {
			reject(false);
		} else {
			resolve(true);
		}
	});
}

function checkNewUser(openid) {
	return new Promise(function(resolve, reject) {
		uniCloud.callFunction({
			name: 'get',
			data: {
				collection: 'uni-id-users',
				where: {
					wx_openid: openid
				}
			},
			success: (res) => {
				if (res.result.affectedDocs == 0) {
					resolve(true);
				} else if (res.result.affectedDocs == 1) {
					reject(false);
				}
			}
		})

	});
}

function nowTime() {
	var createDate = new Date()
	return createDate.toISOString().slice(0, 10) + ' ' + createDate.getHours() + ':' + createDate.getMinutes()
}

module.exports = {
	checkNewUser,
	checkLogin,
	checkUserInfo,
	nowTime
};
